package com.rxh.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: 陈俊雄
 * Date: 2018/7/16
 * Time: 11:00
 * Project: Management
 * Package: com.rxh.utils
 */
public class DateUtils {

    private final static Logger logger = LoggerFactory.getLogger(DateUtils.class);

    /**
     * 设置结束时间+1天(用于查询)
     *
     * @param endDate 结束时间
     * @return 结束时间
     */
    public static Date setEndDate(Date endDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(endDate);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        endDate = calendar.getTime();
        return endDate;
    }

    public static Date addDay(Date date, int add) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, add);
        date = calendar.getTime();
        return date;
    }

    public static Date dateFormat(DateFormat dateFormat, String dateStr) {
        try {
            return dateFormat.parse(dateStr);
        } catch (ParseException e) {
            logger.error("日期转换异常！", e);
        }
        return null;
    }
}
